﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Linq;
using System.Collections.Generic;
using LocalDBDemo;

namespace DemoWP7
{
    public class DBHelper
    {
        private const string ConnectionString = @"isostore:/Employee.sdf";

        public static void CreateDatabase()
        {
            using (var context = new EmployeeDataContext(ConnectionString))
            {
                if (!context.DatabaseExists())
                {
                    // create database if it does not exist
                    context.CreateDatabase();
                }
            }
        }

        public static void DeleteDatabase()
        {
            using (var context = new EmployeeDataContext(ConnectionString))
            {
                if (context.DatabaseExists())
                {
                    // delete database if it exist
                    context.DeleteDatabase();
                }
            }
        }

        public static void AddEmployee(Employee1 employee)
        {
            using (var context = new EmployeeDataContext(ConnectionString))
            {
                if (context.DatabaseExists())
                {
                    context.Employees.InsertOnSubmit(employee);
                    context.SubmitChanges();
                }
            }
        }

        public static IList<Employee1> GetEmployees()
        {
            IList<Employee1> employees;
            using (var context = new EmployeeDataContext(ConnectionString))
            {
                employees = (from emp in context.Employees select emp).ToList();
            }

            return employees;
        }
    }

}
